/**
 * @FileName: MyApplicationPreparedEventListener.java
 * @Package: com.springboot.listener
 * @author lig134
 * @created 2017/3/7 10:43
 * <p>
 * Copyright 2015 ziroom
 */
package com.springboot.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * <p></p>
 * <p>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author lig134
 * @version 1.0
 * @since 1.0
 */
public class MyApplicationPreparedEventListener implements ApplicationListener<ApplicationPreparedEvent> {
    Logger logger= LoggerFactory.getLogger(MyApplicationPreparedEventListener.class);
    @Override
    public void onApplicationEvent(ApplicationPreparedEvent applicationPreparedEvent) {
        ConfigurableApplicationContext contex = applicationPreparedEvent.getApplicationContext();
        //todo
        passContextInfo(contex);
    }

    /**
     * 传递上下文 做一些额外的操作
     *
     * @param ctx
     */
    private void passContextInfo(ApplicationContext ctx) {
        //do
        Long date=ctx.getStartupDate();
        String applicationName=ctx.getApplicationName();
        logger.info("startDate:{},applicationName:{}",date,applicationName);
    }
}